package cn.wsalix.admin.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.anlaser.repository.RelatedRepository;
import cn.wsalix.admin.entity.RoleMenu;
import cn.wsalix.admin.entity.SysMenu;
import cn.wsalix.admin.entity.SysRole;
import cn.wsalix.admin.form.RoleMenuForm;

public interface RoleMenuRepository extends RelatedRepository<RoleMenuForm,RoleMenu,SysRole,SysMenu> {

	@Query("select rm from RoleMenu rm,SysRole r where rm.menu.id = :menuId and rm.role.id = r.id ")
	public List<SysRole> findRolesByMenuId(@Param("menuId") Long menuId);

	@Query("select m from RoleMenu rm,SysMenu m where rm.role.id = :roleId and rm.menu.id = m.id")
	public List<SysMenu> findMensByRoleId(@Param("roleId") Long roleId);

	
	@Query("select rm from RoleMenu rm where rm.role.id = :roleId and rm.menu.id = :menuId")
	public RoleMenu findRoleAndMenuOne(@Param("roleId") Long roleId,
			@Param("menuId") Long menuId);

	@Query("select rm from RoleMenu rm where rm.role.id = :roleId")
	public List<RoleMenu> findByRoleId(@Param("roleId") Long roleId);
	
	@Query("select rm from RoleMenu rm where rm.menu.id = :menuId")
	public List<RoleMenu> findByMenuId(@Param("menuId") Long menuId);

}
